<?php
namespace Core\Mvc;

use Phalcon\Mvc\Router as PhalconRouter;

class Router extends PhalconRouter
{
    public function __construct($defaultRoutes = false)
    {
        parent::__construct($defaultRoutes);
        $this->initialize();
    }

    public function initialize()
    {
        global $di;
        $routes = $di->getShared('config')->cache('routes');
        $routes += [
            '_default' => [
                'namespace' => 'Modules\Core\Controllers',
                'module' => 'Core',
                'controller' => 'Index',
                'action' => 'Index',
            ],
            '_notFound' => [
                'namespace' => 'Modules\Core\Controllers',
                'module' => 'Core',
                'controller' => 'Index',
                'action' => 'NotFound',
            ]
        ];
        $this->removeExtraSlashes(true);
        $this->setDefaults($routes['_default']);
        $this->notFound($routes['_notFound']);
        unset($routes['_default']);
        unset($routes['_notFound']);
        foreach ($routes as $name => $route) {
            $this->add($route['pattern'], $route['paths'], $route['httpMethods'])->setName($name);
        }
    }
}
